package cn.tedu.controller;

import cn.tedu.pojo.Item;
import cn.tedu.pojo.Order;
import cn.tedu.pojo.User;
import cn.tedu.service.OrderService;
import cn.tedu.util.JsonResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

@RestController
@Slf4j
public class OrderController {
    @Autowired
    private OrderService orderService;

    @GetMapping("/{orderId}")
    public JsonResult getOrder(@PathVariable String orderId){
        Order order = orderService.getOrder(orderId);
        return JsonResult.ok(order);
    }

    @GetMapping("/addOrder")
    public JsonResult addOrder(){
        List<Item> itemList = new ArrayList<>();
        itemList.add(new Item(11, "明月勾", 1));
        itemList.add(new Item(12, "长生剑", 1));
        itemList.add(new Item(12, "霸王枪", 1));

        Order order = new Order();
        order.setId("15215412").setUser(new User().setId(5)).setItems(itemList);
        orderService.addOrder(order);
        return JsonResult.ok().msg("新增成功");
    }
}
